﻿var InitPostUrl = "../Handler/AdminHandler.ashx";
var InitCommonUrl = "../Handler/CommonHandler.ashx";
var YXQ = {
    Manager: {},
    Common: {}
}
YXQ.Common = {
    SelAll: function () {
        $("input:checkbox").each(function (i) {
             this.checked = true; 

        });

    },
    NoSelAll: function () {
        $("input:checkbox").each(function (i) {
            this.checked = false;
        });
    },
    ConvertCH: function (title, control) {

        YXQCore.Form.PostData(
               InitPostUrl,
                { OpType: "GetPY", PostData: title },
                function (e) {

                    $("[" + control + "]").val(e.ResultMessage);

                });

    },
    GetCheckboxItem: function () {
        var allSel = "";
        $("input:checkbox").each(function (i) {
            if (this.checked) {
                allSel += this.value + ",";
            }
        });
        return allSel.substring(0, allSel.length - 1);

    },
    GetOneItem: function () {
        var allSel = "";
        $("input:checkbox").each(function (i) {
            if (allSel == "") {
                allSel = this.value;
            }
        });

    },
    DelOneById: function (optype, id, rtnUrl) {
        YXQCore.Form.PostData(
            InitPostUrl,
            { OpType: optype, PostData: id },
            function (e) {
                if (e.ResultMessage == "Success") {
                    YXQ.Common.Message("成功删除！");
                    window.location.href = "../manager/" + rtnUrl;
                }
            });
    },
    CheckNull: function (ctrol, message) {
        if ($("[Datafield=" + ctrol + "]").length > 0) {
            if ($("[Datafield=" + ctrol + "]").val() == "") {
                YXQ.Common.Message(message);
                return false;
            }
        } else if ($("#" + ctrol).val() == "") {
            YXQ.Common.Message(message);
            return false;
        }

    },
    Message: function (msg) {
        $.messager.alert("温馨提示", msg);
        return;
    },
    UnBlock: function () {
        window.parent.location.reload();
        window.parent.unblock();
    },      
    Block: function (url, cid) {
        var demo = $("#showDemoBox");
        var iframe = demo.find("#iframe");
        if (cid != null || cid != undefined) {
            iframe.attr("src", url + "?id=" + cid + "&day=" + new Date());
        } else {
            iframe.attr("src", url);
        }
        $.blockUI({
            message: demo, css: {
                width: '1000px',
                left: ($(window).width() - 1000) / 2 + 'px',
                height: ($(window).height()) + 'px',

            }
        });
    }

};

YXQ.Manager = {
    Login: function () {
        var uname = $("#username").val();
        var password = $("#password").val();
        
        if (uname == "") {
            YXQ.Common.Message("对不起请输入用户名！");
            return;
        }
        if (password == "") {
            YXQ.Common.Message("对不起请输入密码！");
            return;
        }

        YXQCore.Form.PostData(
        InitPostUrl,
        { OpType: "ChkLogin", PostData: uname, strValue: password},
        function (e) {
            window.location.href = "manager/index.aspx";
            if (e.ResultMessage == "LoginFailed") {
                YXQ.Common.Message("对不起，用户名或密码错误！");
                return;
            } else if (e.ResultMessage == "SessionCodeFailed") {
                YXQ.Common.Message("对不起，验证码输入有误！");
                return;
            }  else if (e.ResultMessage == "Success") {
                window.location.href = "manager/index.aspx";
            }
        });

    },
     CloseDialog:function(){
         $("#openwin").dialog("close");
         
    },
     OpenDialog: function (url, tt, w, h) {
         if (tt == undefined) {
             tt = "查看详情";
         }
         if (w == undefined) {
             w = $(window).width() - 100;
         }
         if (h == undefined) {
             h = $(window).height() - 100;
         }

        $("#openwin").dialog({
            title: tt,
            href: url,
            width: w,
            height: h,
            modal: true,
            minimizable: true,
            maximizable: true,
            cache:false
            
        });
        
        $("#openwin").dialog("open");
       
    },
     DelNav: function (navid) {
         YXQCore.Form.PostData(InitCommonUrl, { OpType: "DelNavId", PostData: navid },
             function (data) {
                 if (data.ResultMessage == "Success") {
                     YXQ.Common.Message("操作已成功");
                     window.location.reload();
                     return;
                 }
             });
     },
     CommonDel: function (tbname, id) {
         YXQCore.Form.PostData(InitCommonUrl, { OpType: "Del", PostData: tbname, strValue: id },
             function (data) {
                 if (data.ResultMessage == "Success") {
                     YXQ.Common.Message("操作已成功！");
                     window.location.reload();
                 }
             });
     },
     SaveArea: function (item) {
         var json = null;
         var jsonstring = "";
         if (item == "") {
             var tbDetail = $("#tbDetail");
             json = YXQCore.Form.GetDivFormData(tbDetail);
             jsonstring = $.toJSON(json);
         } else {
             jsonstring = item;
         }
          
         YXQCore.Form.PostData(InitCommonUrl, { OpType: "SaveArea", PostData: jsonstring },
             function (data) {
                 if (data.ResultMessage == "Success") {
                     YXQ.Common.Message("操作已成功！");
                     if (item != "") {
                         $('#tg').treegrid("reload");
                         YXQ.Manager.CloseDialog();
                     }
                 }
         });
     }
}